<?php
/**
 * 作者数据模型
 *
 * @author sandy
 *
 */
class authorModel extends Model{

	public function get_all_author($page_info = array()){
		
		$return = array('result'=>'','total'=>0);
		
		$sql = "SELECT * FROM #__author ORDER BY author_id DESC";
		$sql_count = "SELECT count(*) FROM #__author";
		
		if (!empty($page_info)){
			$this->db->set_query($sql,$page_info['offset'],$page_info['limit']);
		} else {
			$this->db->set_query($sql);
		}
		$return['result'] = $this->db->get_all();
		
		
		$this->db->set_query($sql_count);
		$return['total'] = $this->db->get_one();
		
		return $return;
	}
	
	public function get_author($author_id) {
		$sql = "SELECT * FROM #__author WHERE author_id = $author_id";
		$this->db->set_query($sql);
		
		return $this->db->get_row();
	}
	
	public function add_author($author_info){
		
		$insert_info = array(
				'author_name' => $author_info['author_name'],
				'letter' => $author_info['letter'],
		);
		
		return $this->db->insert("#__author",$insert_info);
	}
	
	public function update_author($author_info){
		
		$update_info = array(
				'author_name' => $author_info['author_name'],
				'letter' => $author_info['letter'],
		);
		
		return $this->db->update('#__author',$update_info,'author_id = '.$author_info['author_id']);
	}
}